package com.applet.message.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.context.request.async.DeferredResult;
import springfox.documentation.builders.ParameterBuilder;
import springfox.documentation.schema.ModelRef;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.service.Parameter;
import springfox.documentation.service.VendorExtension;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.ArrayList;
import java.util.List;

import static springfox.documentation.builders.PathSelectors.regex;

/**
 * Created by admin on 2019/12/10 0010.
 */
@Configuration
@EnableSwagger2
public class SwaggerConfig {

    @Value("${swagger.show}")
    private boolean swaggerShow = true;

    @Bean
    public Docket xwalletAApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .enable(swaggerShow)
                .groupName("ISTPOS接口")
                .genericModelSubstitutes(DeferredResult.class)
// .genericModelSubstitutes(ResponseEntity.class)
                .useDefaultResponseMessages(false)
                .forCodeGeneration(true)
                .pathMapping("/")// base，最终调用接口后会和paths拼接在一起
                .select()
                .paths(regex("/v1/api/*/.*"))//过滤的接口
                .build()
                .apiInfo(xwalletApiInfo());
    }

    private ApiInfo xwalletApiInfo() {
        ApiInfo apiInfo = new ApiInfo("ISTPOS 接口",
                "ISTPOS 接口说明文档",
                "0.1",
                "暂无",
                new Contact("Popeye", "", ""),
                "暂无",
                "暂无",
                new ArrayList<VendorExtension>());
        return apiInfo;
    }
}
